package com.yonyou.pmclouds.discuss.impl;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.discuss.entity.DiscussNoticeVO;
import com.yonyou.pmclouds.discuss.entity.DiscussionVO;
import com.yonyou.pmclouds.discuss.itf.SpecifiedTypeDiscussProcessor;

import java.util.HashMap;
import java.util.Map;

/**
 * 生成通知消息，可以考虑使用规则引擎来增强可配置性
 */
public class DiscussProcessor {
    private Map<String, SpecifiedTypeDiscussProcessor> processors = new HashMap<>();

    public DiscussNoticeVO[] generateNotice(DiscussionVO discussion) throws BusinessException {
        SpecifiedTypeDiscussProcessor processor = processors.get(discussion.getRelateType());
        if (processor == null) {
            return null;
        }
        return processor.generateNotice(discussion);
    }

    public void addProcessor(SpecifiedTypeDiscussProcessor processor) {
        if (processor != null) {
            processors.put(processor.getRelateType(), processor);
        }
    }
}
